import app from '../../App.vue';
const baseurl="url";
console.log(app.globalData)
const request = (url, options) => {
  return new Promise((resolve, reject) => {
    wx.request({
      url: `${baseurl}${url}`,
      method: options.method,
      // data: options.method === 'GET' ? options.data : JSON.stringify(options.data),
      data:options.data,
      header: {
        'content-Type': 'application/json',
        "Authorization": app.globalData.authorization ? app.globalData.authorization:''
      },
      success(res) {
        if (res.data.code === "success"||res.data.status) {
          // 返回data
          resolve(res.data)
        } else {
        if(res.data.code=='U204'){
			// uni.reLaunch({
			// 	url:'/pages/login/newlogin'
			// })
		}
          reject(res.data)
        }
      },
      fail(err) {
       
        console.log(err)
        reject(err.data)
      }
    })
  })
}

const get = (url, options = {}) => {
  return request(url, { method: 'GET', data: options })
}

const post = (url, options) => {
  return request(url, { method: 'POST', data: options })
}

const put = (url, options) => {
  return request(url, { method: 'PUT', data: options })
}

// 不能声明DELETE（关键字）
const remove = (url, options) => {
  return request(url, { method: 'DELETE', data: options })
}

export default {
  get,
  post,
  put,
  remove
}